package com.example.day07_zhongji;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MediaActivity extends AppCompatActivity {

    private Button mBu1;
    private Button mBu2;
    private Button mBu3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_media);
        initViews();
    }

    private void initViews() {
        MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.asd);
        mBu1 = findViewById(R.id.bu1);
        mBu2 = findViewById(R.id.bu2);
        mBu3 = findViewById(R.id.bu3);
        mBu1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mediaPlayer.start();
            }
        });
        mBu2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mediaPlayer.pause();
            }
        });
        mBu3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mediaPlayer.start();
                mediaPlayer.reset();
            }
        });
    }
}
